@extends('layouts.admin-iframe-base')


@section('css')

@stop

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        用户管理
        <small>用户电站</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">首页</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <!-- Your Page Content Here -->
    <div class="row">
        <div class="col-md-3">
            <div class="box box-primary">
                <div class="box-body box-profile">
                    <img class="profile-user-img img-responsive img-circle" src="/dist/admin/img/default.png"
                         alt="User profile picture">

                    <h3 class="profile-username text-center">{{$user->name}}</h3>

                    <p class="text-muted text-center">{{$user->email}}</p>

                    <ul class="list-group list-group-unbordered">
                        <li class="list-group-item">
                            <b>手机</b> <a class="pull-right">{{$user->phone}}</a>
                        </li>
                        <li class="list-group-item">
                            <b>拥有的电站</b> <a class="pull-right">{{$site_total}}</a>
                        </li>
                        <li class="list-group-item">
                            <b>创建时间</b> <a class="pull-right">{{$user->created_at}}</a>
                        </li>
                    </ul>

                    <a href="/admin/site/create-user-site?user_id={{$user->id}}" class="btn btn-primary btn-block"><b>添加电站</b></a>
                </div>
                <!-- /.box-body -->
            </div>
        </div>

        <div class="col-md-9">
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#sites" data-toggle="tab">全部电站</a></li>
                </ul>
                <div class="tab-content">
                    <div class="active tab-pane" id="sites">
                        <table id="J-dt" class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>地址</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                    <!-- /.tab-pane -->

                </div>
                <!-- /.tab-content -->
            </div>
        </div>
    </div>
    <!-- /.box -->

</section>
<!-- /.content -->


@stop

@section('js')
    <script>

        $(function () {
            $('#J-dt').DataTable({
                "paging": true,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": false,
                "ajax": {
                    "url": "/admin/site/user-site?user_id={{$user->id}}",
                    "type": "post"
                },
                "columns": [
                    {"data": "name"},
                    {"data": "address"},
                    {"data": "id"},
                ],
                "columnDefs": [
                    {
                        "targets": -1,
                        "render": function (data, type, row) {
                            var str = '<a href="/admin/site/edit-user-site?id=' + data + '&user_id={{$user->id}}" class="btn btn-success btn-sm">编辑</a> &nbsp;';
                            str = str + '<a href="javascript:;" class="btn btn-danger btn-sm J-del-btn" data-id="' + data + '">删除</a>';
                            return str;
                        }
                    },
                    {
                        "targets": 0,
                        "render": function (data, type, row) {
                            return '<a href="/admin/site/user-site-detail?id=' + row.id + '&user_id={{$user->id}}">' + data + '</a>';
                        }
                    }


                ]
            });
            $('#J-dt').on('click', '.J-del-btn', function () {
                var id = $(this).data('id');
                var params = {
                    id: id,
                    user_id: '{{$user->id}}'
                };
                $.post('/admin/site/delete-user-site', params, function (res) {
                    if (res.status == 1) {
                        alert('删除成功！');
                        window.location.reload();
                    } else {
                        alert(res.error_msg);
                    }
                }, 'json');
            });


        });


    </script>
@stop